/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.click.app.webapp.action;

import com.click.app.DateFormatChanger;
import com.click.app.model.LaundryItem;
import com.click.app.model.LaundryRequest;
import com.click.app.model.LaundryRequestItem;
import com.click.app.model.LaundryType;
import com.click.app.model.ModelSize;
import com.click.app.model.PantDesign;
import com.click.app.model.SizeRank;
import com.click.app.model.TradeMark;
import com.click.app.service.GenericManager;
import com.click.app.service.LaundryItemManager;
import com.click.app.service.LaundryRequestItemManager;
import com.click.app.service.LaundryStorageManager;
import com.click.app.service.PantDesignManager;
import com.click.app.service.SeamStorageManager;
import com.click.app.webapp.reportObjects.LaundryReceptionTable;
import com.click.app.webapp.reportObjects.LaundryRequestTable;

import java.util.List;
import java.util.Set;

/**
 * @author Joel Chuca Condo
 */
public class ClothesStorageWashedAction extends BaseAction {

    private PantDesignManager pantDesignManager;
    private SeamStorageManager seamStorageManager;
    private LaundryRequestItemManager laundryRequestItemManager;
    private GenericManager<LaundryRequest, Long> laundryRequestManager;
    private GenericManager<TradeMark, Long> tradeMarkManager;
    private GenericManager<LaundryType, Long> laundryTypeManager;
    private GenericManager<SizeRank, Long> sizeRankManager;
    private LaundryItemManager laundryItemManager;
    private LaundryStorageManager laundryStorageManager;
    private LaundryRequest laundryRequest;
    private LaundryRequestItem laundryRequestItem;
    private PantDesign pantDesign;
    private List laundryRequests;
    private List laundryRequestItems;
    private List laundryTypes;
    private List pantDesigns;
    private Set<ModelSize> modelSizes;
    private List<LaundryItem> laundryItems;
    private String[] quantities;
    private Long id;
    private Long idLaundryRequest;
    private LaundryReceptionTable laundryReceptionTable;
    private String receivedDate;
    private LaundryRequestTable laundryRequestTable;

    public void setLaundryRequestItemManager(LaundryRequestItemManager laundryRequestItemManager) {
        this.laundryRequestItemManager = laundryRequestItemManager;
    }

    public void setLaundryRequestManager(GenericManager<LaundryRequest, Long> laundryRequestManager) {
        this.laundryRequestManager = laundryRequestManager;
    }

    public void setLaundryTypeManager(GenericManager<LaundryType, Long> laundryTypeManager) {
        this.laundryTypeManager = laundryTypeManager;
    }

    public void setPantDesignManager(PantDesignManager pantDesignManager) {
        this.pantDesignManager = pantDesignManager;
    }

    public void setSeamStorageManager(SeamStorageManager seamStorageManager) {
        this.seamStorageManager = seamStorageManager;
    }

    public void setTrademarkManager(GenericManager<TradeMark, Long> trademarkManager) {
        this.tradeMarkManager = trademarkManager;
    }

    public void setSizeRankManager(GenericManager<SizeRank, Long> sizeRankManager) {
        this.sizeRankManager = sizeRankManager;
    }

    public void setLaundryItemManager(LaundryItemManager laundryItemManager) {
        this.laundryItemManager = laundryItemManager;
    }

    public void setLaundryStorageManager(LaundryStorageManager laundryStorageManager) {
        this.laundryStorageManager = laundryStorageManager;
    }

    public List getLaundryRequestItems() {
        return laundryRequestItems;
    }

    public List getLaundryRequests() {
        return laundryRequests;
    }

    public List getLaundryTypes() {
        return laundryTypes;
    }

    public List<LaundryItem> getLaundryItems() {
        return laundryItems;
    }

    public String[] getQuantities() {
        return quantities;
    }

    public void setQuantities(String[] quantities) {
        this.quantities = quantities;
    }

    public List getPantDesigns() {
        return pantDesigns;
    }

    public Set<ModelSize> getModelSizes() {
        return modelSizes;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getIdLaundryRequest() {
        return idLaundryRequest;
    }

    public void setIdLaundryRequest(Long idLaundryRequest) {
        this.idLaundryRequest = idLaundryRequest;
    }

    public LaundryRequest getLaundryRequest() {
        return laundryRequest;
    }

    public void setLaundryRequest(LaundryRequest laundryRequest) {
        this.laundryRequest = laundryRequest;
    }

    public LaundryRequestItem getLaundryRequestItem() {
        return laundryRequestItem;
    }

    public void setLaundryRequestItem(LaundryRequestItem laundryRequestItem) {
        this.laundryRequestItem = laundryRequestItem;
    }

    public LaundryReceptionTable getLaundryReceptionTable() {
        return laundryReceptionTable;
    }

    public PantDesign getPantDesign() {
        return pantDesign;
    }

    public void setPantDesign(PantDesign pantDesign) {
        this.pantDesign = pantDesign;
    }

    public String getReceivedDate() {
        receivedDate = DateFormatChanger.changeDatetoString(laundryRequest.getEndDate());
        return receivedDate;
    }

    public void setReceivedDate(String receivedDate) {
        this.receivedDate = receivedDate;
        laundryRequest.setEndDate(DateFormatChanger.changeStringtoDate(receivedDate));    
    }

    public LaundryRequestTable getLaundryRequestTable() {
        return laundryRequestTable;
    }

    public String clothesStorageWashedList() {
        laundryRequests = laundryRequestManager.getAll();
        return SUCCESS;
    }

    public String list() {
        System.out.println("ChothesStorageWashedAction -> list()");
        if (idLaundryRequest != null) {
            laundryRequest = laundryRequestManager.get(idLaundryRequest);
            getSession().setAttribute("laundryRequest", laundryRequest);
        } else {
            laundryRequest = ((LaundryRequest) getSession().getAttribute("laundryRequest"));
        }

        if (laundryRequest != null) {
            //update
//            laundryRequest = laundryRequestManager.get(laundryRequest.getId());
//            modelSizes = sizeRankManager.get(laundryRequest.getSizeRank().getId()).getModelSizes();
//            getSession().setAttribute("modelSizes", modelSizes);
//            laundryRequestTable = new LaundryRequestTable(laundryRequest.getLaundryRequestItems(), laundryItemManager, modelSizes);

        } else {
            System.out.println("ChothesStorageWashedAction -> end list()... null ");
            return ERROR;
        }
        System.out.println("ChothesStorageWashedAction -> end list()");
        return SUCCESS;
    }

    public String listFails() {

        if (idLaundryRequest != null) {
            laundryRequest = laundryRequestManager.get(idLaundryRequest);
            getSession().setAttribute("laundryRequest", laundryRequest);
        } else {
            laundryRequest = ((LaundryRequest) getSession().getAttribute("laundryRequest"));
        }

        if (laundryRequest != null) {
            //update
//            laundryRequest = laundryRequestManager.get(laundryRequest.getId());
//            modelSizes = sizeRankManager.get(laundryRequest.getSizeRank().getId()).getModelSizes();
//            getSession().setAttribute("modelSizes", modelSizes);
//            laundryReceptionTable = new LaundryReceptionTable(laundryRequest.getLaundryRequestItems(), laundryItemManager, modelSizes);
//            if (!(laundryReceptionTable.isCorrect())) {
//                errorMessage(getText("Can't show the table "));
//                return ERROR;
//            }
        } else {
            System.out.println("laundryRequest is null");
            return ERROR;
        }
        return SUCCESS;
    }

   

    
}
